<?php

namespace Common\Model;

use Think\Model;

class AnswerReplyModel extends Model
{
    protected $_validate = array(
        array('content', 'require', '内容必须填写'),
        array('type', 'require', '追加类型必须填写'),
    );

    protected $_auto = array(
        array('addtime', 'time', 1, 'function'),
    );

    /**
     * 获取答案回复列表
     * @param string $rid
     * @return array
     */
    public function get_answer_reply($rid = '')
    {
        $map['rid'] = intval($rid);
        $list       = $this->where($map)->order('id ASC')->select();
        foreach ($list as $v) {
            $v['addtime_str'] = daterange($v['addtime']);
            $v['content']     = ytata_strip_tags($v['content']);
            $li[]             = $v;
        }
        return $li;
    }

    // 回答追加
    public function reply_supp($data, $rid, $uid)
    {
        if (!$this->create($data)) {
            $ret['status'] = false;
            $ret['msg'] = $this->getError();
            return $ret;
        } else {
            $this->rid = $rid;
            $this->uid = $uid;
        }
        $newid = $this->add();
        if (!$newid) {
            $ret['status'] = false;
            $ret['msg'] = '保存失败';
            return $ret;
        }
        # 问题追加相关处理

        $ret['status'] = true;
        $ret['msg'] = '保存成功';
        return $ret;
    }
}